<template>
  <div class="containerBox">
    <div class="container">
      <div class="filterBox">
        区域
        <el-cascader
          v-model="areaId"
          :options="areasOptions"
          @change="getAreaId"
          clearable
          filterable
          :props="{ checkStrictly: true }"
          style="marginleft: 10px; marginright: 30px"
        ></el-cascader
        >行业
        <el-select
          v-model="industryId"
          @change="getIndustryId"
          style="margin-left: 10px"
          clearable
          filterable
        >
          <el-option
            v-for="item in industryOptions"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          ></el-option>
        </el-select>
      </div>

      <div class="rightContent">
        <div class="applicationMarketBox">
          <div class="keyBox">
            <div class="titleZw">政务指标</div>
            <div
              v-for="(item, index) in statistic"
              :key="index"
              :style="{
                marginBottom: index === statistic.length - 1 ? '0' : '10px',
              }"
            >
              <div style="float: right">
                {{ index === 0 ? item.value : item.value * 100 + '%' }}
              </div>
              <div>{{ item.name }}</div>
            </div>
          </div>
        </div>
        <div class="governmentAssess">
          <div class="title">政务考核</div>
          <div class="nothing">
            <div>暂无考核数据</div>
          </div>
        </div>
      </div>
      <div class="leftContent">
        <div class="realTimeMonitoring">
          <div class="options">
            <div @click="changeOption(0)">
              <!-- <div
                :style="{marginRight:'20px',color:option===0? '#009588':'#666'}"
              >风险项目（{{unPerfectProjectCount}}个）</div> -->
              <div
                :style="{
                  marginRight: '20px',
                  color: option === 0 ? '#009588' : '#666',
                }"
              >
                风险项目（{{ 2 }}个）
              </div>
              <div
                class="greenLine"
                :style="{ opacity: option === 0 ? '1' : '0' }"
              ></div>
            </div>
            <div @click="changeOption(1)">
              <!-- <div
                :style="{marginRight:'20px',color:option===1? '#009588':'#666'}"
              >优质项目（{{perfectProjectCount}}个）</div> -->
              <div
                :style="{
                  marginRight: '20px',
                  color: option === 1 ? '#009588' : '#666',
                }"
              >
                优质项目（{{ 1 }}个）
              </div>
              <div
                class="greenLine"
                :style="{ width: '79%', opacity: option === 1 ? '1' : '0' }"
              ></div>
            </div>
            <div @click="changeOption(2)">
              <div
                :style="{
                  marginRight: '20px',
                  color: option === 2 ? '#009588' : '#666',
                }"
              >
                奖励企业（0个）
              </div>
              <div
                class="greenLine"
                :style="{ width: '79%', opacity: option === 2 ? '1' : '0' }"
              ></div>
            </div>
            <div @click="changeOption(3)">
              <div :style="{ color: option === 3 ? '#009588' : '#666' }">
                惩戒企业（0个）
              </div>
              <div
                class="greenLine"
                :style="{ width: '79%', opacity: option === 3 ? '1' : '0' }"
              ></div>
            </div>

            <!-- <div @click="changeOption(2)">
                <div :style="{color:option===2? '#009588':'#666'}">黑名单企业（--个）</div>
                <div class="greenLine" :style="{width:'95%',opacity:option===2?'1':'0'}"></div>
            </div>-->
          </div>
          <div class="title" style="width: 30%">实时监控</div>

          <div class="searchBox">
            <div class="projectBox">
              <div class="inputBox">
                <el-input
                  :placeholder="
                    '输入' +
                    (option === 0 || option === 1 ? '项目' : '企业') +
                    '名称'
                  "
                  clearable
                  v-model="filterField.projectName"
                  class="input"
                >
                  <el-button
                    slot="append"
                    icon="el-icon-search"
                    @click="searchTable()"
                  ></el-button>
                </el-input>
              </div>
              <el-row
                v-for="(item, index) in projects"
                :key="index"
                class="projects"
                :style="{
                  marginBottom: index === projects.length - 1 ? '0' : '10px',
                }"
                @click.native="skipPage(item.projectName)"
              >
                <el-col
                  :class="
                    item.gradeLevel === 'A' || item.gradeLevel === 'B'
                      ? 'normalLevel'
                      : 'warningLevel'
                  "
                  >{{ item.gradeLevel }}</el-col
                >
                <el-col class="projectName" :span="10">{{
                  item.projectName
                }}</el-col>
              </el-row>
              <div v-if="isShow" class="emptyBox">
                <div class="empty">
                  <emptyTable
                    :emptyText="
                      '暂无相关' +
                      (option === 0 || option === 1 ? '项目' : '企业')
                    "
                  ></emptyTable>
                </div>
              </div>
              <div class="paginationBox">
                <el-pagination
                  small
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page.sync="pageNo"
                  :page-size="pageSizeNumber"
                  layout="total, prev, pager, next"
                  :total="total"
                  ref="pagination"
                ></el-pagination>
              </div>
            </div>
          </div>
          <div class="chartBox">
            <div class="chartBoxTitle">{{ chartBoxTitle[option] }}</div>
            <div id="chart1" class="chart1"></div>
          </div>
        </div>
        <div class="projectsRating">
          <div class="title">
            <div>
              在建项目评级
              <span class="iconfont projectsRatingIcon">&#xe7b6;</span>
            </div>
          </div>
          <div id="chart2" class="chart2"></div>
        </div>
        <div class="govAffairIndicator">
          <div class="title">
            <div>政务指标趋势</div>
          </div>
          <div id="chart3" class="chart3"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex'

export default {
  name: 'dynamicSupervision',
  data() {
    return {
      api: {
        detail: 'api-ps/projectscorestats/expand/detail',
        month: 'api-ps/projectscorestats/expand/month',
        year: 'api-ps/projectscorestats/expand/year',
        listbymonitor: 'api-ps/projectscore/expand/listbymonitor',
      },
      areaId: '',
      industryId: '',
      option: 0,
      chartBoxTitle: [
        '风险项目数量',
        '优质项目数量',
        '奖励企业数',
        '惩戒企业数',
        // "有在建项目的黑名单企业",
      ],
      searchInfo: '',
      projects: [],
      statistic: [],
      unPerfectProjectCount: '',
      perfectProjectCount: '',
      monthData: [],
      halfYearDate: [],
      filterField: {
        projectName: '',
        projectLevel: 'C,D',
        areaId: '',
        industryId: '',
        status: 'STARTED', //风险项目默认传项目状态已开工
      },
      isShow: false,
      optionsLeft: 0,
      pageNo: 1,
      total: 0,
      pageSizeNumber: 10,
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptions']) },
  created() {
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    this.getIndustry({})
    this.getProjectStatistic()
    this.getProjectRating()
    this.getGovAffairIndicator()
    var that = this
    this.$nextTick(function () {
      that.searchTable()
    })
  },
  methods: {
    ...mapActions(['getAreas', 'getIndustry']),
    getTableListData(currentPage, pageSize) {
      if (!currentPage) {
        if (this.pageSize) {
          this.pageSizeNumber = this.pageSize
        } else {
          this.pageSizeNumber = 20
        }
        this.$refs.pagination.internalCurrentPage = 1
      }
      var pageS
      if (pageSize) {
        pageS = pageSize
      } else if (this.pageSize) {
        pageS = this.pageSize
      } else {
        pageS = 20
      }
      var data = {
        pageNo: currentPage ? currentPage : 1,
        pageSize: pageS,
      }

      if (this.filterField) {
        if (this.isPackParams) {
          data.params = JSON.stringify(this.filterField)
        } else {
          data = Object.assign(data, this.filterField)
        }
      }
      this.axios({
        method: 'post',
        url: this.api.listbymonitor,
        data: data,
      })
        .then((response) => {
          if (!response.data.hasError) {
            if (response.data.result.results) {
              this.tableList = response.data.result.results
            } else {
              this.tableList = []
            }
            //传值到父组件
            //   this.$emit("getList", this.tableList);
            this.getTableList(this.tableList)
            this.total = response.data.result.total
          } else {
            this.$message({
              message: response.data.errorMsg,
              type: 'warning',
            })
          }
        })
        .catch((error) => {})
    },
    //每页显示多少条
    handleSizeChange(val) {
      // 选中条数变为第一页
      this.pageNo = 1
      // this.$emit("getPageSize",val);
      this.pageSizeNumber = val
      this.$refs.pagination.internalCurrentPage = this.pageNo
      this.getTableListData(this.pageNo, val)
    },
    //显示第几页
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.getTableListData(val, this.pageSizeNumber)
    },
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
      this.filterField.areaId = areaId
      this.getProjectStatistic()
      this.getProjectRating()
      this.getGovAffairIndicator()
      this.searchTable()
    },
    getIndustryId() {
      this.filterField.industryId = this.industryId
      this.getProjectStatistic()
      this.getProjectRating()
      this.getGovAffairIndicator()
      this.searchTable()
    },
    changeOption(e) {
      this.option = e
      switch (e) {
        case 0:
          this.filterField.projectLevel = 'C,D'
          this.filterField.status = 'STARTED'
          this.renderProjectStatistic(this.monthData, true)
          break
        case 1:
          this.filterField.projectLevel = 'A'
          this.filterField.status = ''
          this.renderProjectStatistic(this.monthData, true)
          break
        case 2:
          this.filterField.projectLevel = 'E'
          this.filterField.status = ''
          this.produceFalseData()
          break
        case 3:
          this.filterField.projectLevel = 'E'
          this.filterField.status = ''
          this.produceFalseData()
          break
        default:
          break
      }
      this.searchTable()
    },
    produceFalseData() {
      var baseDate,
        perDay = 24 * 3600 * 1000,
        hasData,
        data = []
      baseDate = new Date().getTime() + perDay
      for (var i = 0; i < 30; i++) {
        var date
        baseDate -= perDay
        date = new Date(baseDate)
        data.unshift({
          date:
            date.getFullYear() +
            '-' +
            (date.getMonth() + 1) +
            '-' +
            date.getDate(),
        })
      }
      this.renderProjectStatistic(data, false)
    },
    skipPage(projectName) {
      this.$router.push({
        path: '/home/projectScore/projectEvaluationList',
        name: 'projectEvaluationList',
        query: {
          projectName: projectName,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/projectScore/projectEvaluationList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    getTableList(data) {
      this.projects = data
      if (data.length < 1) {
        this.isShow = true
      } else {
        this.isShow = false
      }
    },
    //列表查询
    searchTable() {
      this.getTableListData(1, 10)
    },
    getProjectStatistic() {
      this.axios({
        method: 'post',
        url: this.api.month,
        data: {
          areaId: this.filterField.areaId,
          industryId: this.filterField.industryId,
        },
      })
        .then((response) => {
          if (response.data) {
            var data = response.data.result.map(function (item) {
              item.date = item.year + '-' + item.month + '-' + item.day
              return item
            })
            if (data.length < 30) {
              var baseDate,
                perDay = 24 * 3600 * 1000,
                hasData
              if (data.length > 0) {
                baseDate = new Date(this.formatDateTime(data[0].date)).getTime()
              } else {
                baseDate = new Date().getTime() + perDay
              }
              for (var i = data.length; i < 30; i++) {
                var date
                baseDate -= perDay
                date = new Date(baseDate)

                data.unshift({
                  unPerfectProjectCount: 0,
                  perfectProjectCount: 0,
                  date:
                    date.getFullYear() +
                    '-' +
                    (date.getMonth() + 1) +
                    '-' +
                    date.getDate(),
                })
              }
            }
            this.monthData = data
            this.renderProjectStatistic(data, true)
          }
        })
        .catch((error) => {
          console.log('请求失败：' + error.status + ',' + error.statusText)
        })
    },
    //格式化时间 yyyy-mm-dd HH:MM:ss
    formatDateTime(v) {
      v = v.replace(/\-/g, '/') + ' 00:00:00' //注意：指定一个具体的时间转换时间戳，需要yyyy/mm/dd hh:ii:ss格式，yyyy-mm-dd在IE和Safari下是有问题的。
      return v
    },
    getProjectRating() {
      this.axios({
        method: 'post',
        url: this.api.detail,
        data: {
          areaId: this.filterField.areaId,
          industryId: this.filterField.industryId,
        },
      })
        .then((response) => {
          if (response.data) {
            var result = response.data.result
            // this.statistic = [
            //   { name: "在建项目总数：", value: result.projectCount },
            //   { name: "保证金覆盖率：", value: result.depositScale },
            //   { name: "实名制覆盖率：", value: result.realNameScale },
            //   { name: "工资专户覆盖率：", value: result.accountScale },
            //   { name: "银行代发覆盖率：", value: result.issueScale }
            // ];

            //---假数据（后续使用后台接口时，直接删除该段代码即可---begin）---
            this.statistic = [
              { name: '在建项目总数：', value: 5 },
              { name: '保证金覆盖率：', value: 0.6 },
              { name: '实名制覆盖率：', value: 0.6 },
              { name: '工资专户覆盖率：', value: 0.8 },
              { name: '银行代发覆盖率：', value: 0.2 },
            ]
            //---假数据（后续使用后台接口时，直接删除该段代码即可---end）---

            this.unPerfectProjectCount = result.unPerfectProjectCount
            this.perfectProjectCount = result.perfectProjectCount
            var data = {
              level: ['A级', 'B级', 'C级', 'D级'],
              num: [
                result.levelACount,
                result.levelBCount,
                result.levelCCount,
                result.levelDCount,
              ],
              rate: [
                result.levelAScale,
                result.levelBScale,
                result.levelCScale,
                result.levelDScale,
              ],
              total: result.projectLevelCount,
            }
            this.renderProjectRating(data)
          }
        })
        .catch((error) => {
          console.log('请求失败：' + error.status + ',' + error.statusText)
        })
    },
    getGovAffairIndicator() {
      this.axios({
        method: 'post',
        url: this.api.year,
        data: {
          areaId: this.filterField.areaId,
          industryId: this.filterField.industryId,
        },
      })
        .then((response) => {
          if (response.data) {
            var data = response.data.result.map(function (item) {
              item.date = item.year + '年' + item.month + '月'
              return item
            })
            if (data.length < 6) {
              var baseMonth, baseYear, hasData
              if (data.length > 0) {
                baseMonth = data[0].month
                baseYear = data[0].year
                hasData = true
              } else {
                var now = new Date()
                baseMonth = now.getMonth() + 1
                baseYear = now.getFullYear()
                hasData = false
              }

              for (var i = data.length; i < 6; i++) {
                if (hasData) {
                  if (baseMonth === 1) {
                    baseMonth = 12
                    baseYear -= 1
                  } else {
                    baseMonth -= 1
                  }
                }
                data.unshift({
                  projectCount: 0,
                  depositScale: 0,
                  realNameScale: 0,
                  accountScale: 0,
                  issueScale: 0,
                  date: baseYear + '年' + baseMonth + '月',
                })
                if (!hasData) {
                  if (baseMonth === 1) {
                    baseMonth = 12
                    baseYear -= 1
                  } else {
                    baseMonth -= 1
                  }
                }
              }
            }
            this.renderGovAffairIndicator(data)
          }
        })
        .catch((error) => {
          console.log('请求失败：' + error.status + ',' + error.statusText)
        })
    },
    renderProjectStatistic(data, flag) {
      var that = this
      this.$nextTick(() => {
        var myChart1 = this.$echarts.init(document.getElementById('chart1'))
        var dateList = []
        var valueList = []
        //拼接假数据
        var falseData = [
          {
            date: '2019-1-22',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-23',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-24',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-25',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-26',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-27',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-28',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-29',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-30',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-1-31',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
          {
            date: '2019-2-1',
            perfectProjectCount: 1,
            unPerfectProjectCount: 2,
          },
        ]
        var Adata = data.concat(falseData)
        //拼接假数据

        //---假数据（后续使用后台接口时，直接删除该段代码即可---begin）---
        // if (flag) {
        //   if (that.option === 0) {
        //     for (var i = 0; i < 29; i++) {
        //       var j = 20 / (i + 1) + 10;
        //       valueList.push(Math.floor(j));
        //     }
        //     valueList.push(data[data.length - 1].unPerfectProjectCount);
        //   } else if (that.option === 1) {
        //     valueList.push(0);
        //     for (var i = 1; i < 29; i++) {
        //       valueList.push(1);
        //     }
        //     valueList.push(data[data.length - 1].perfectProjectCount);
        //   } else if (that.option === 2) {
        //     valueList.push(0);
        //   } else if (that.option === 3) {
        //     valueList.push(0);
        //   }
        // } else {
        //   for (var i = 0; i < 30; i++) {
        //     valueList.push(0);
        //   }
        // }
        //---假数据（后续使用后台接口时，直接删除该段代码即可---end）---
        Adata.map(function (item) {
          dateList.push(item.date)
          valueList.push(
            that.option === 0
              ? item.unPerfectProjectCount
              : item.perfectProjectCount
          )
        })
        var option = {
          tooltip: {
            trigger: 'axis',

            axisPointer: {
              type: 'line',
              animation: false,
              label: {
                backgroundColor: '#ccc',
                borderColor: '#aaa',
                borderWidth: 1,
                shadowBlur: 0,
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                textStyle: {
                  color: '#222',
                },
              },
            },
            formatter: function (params) {
              return (
                '日期：' +
                params[0].name +
                '<br />' +
                '数量：' +
                params[0].value
              )
            },
          },
          grid: {
            // left: "2%",
            // // right: "1%",
            // top: "5%",
            bottom: '10%',
            containLabel: true,
          },
          xAxis: {
            type: 'category',
            data: dateList,
            name: '天',
            axisLabel: {
              // interval: 1,
              formatter: function (value, idx) {
                var date = new Date(that.formatDateTime(value))
                return idx === 0
                  ? value
                  : [date.getMonth() + 1, date.getDate()].join('-')
              },
            },
            boundaryGap: false,
          },
          yAxis: {
            type: 'value',
            name: '个',
            // axisLabel:{
            //   margin:2
            // }
          },
          series: [
            {
              type: 'line',
              data: valueList,
              hoverAnimation: false,
              symbolSize: 6,
              smooth: true,
              itemStyle: {
                normal: {
                  color: '#5AD8A6',
                },
              },
              showSymbol: false,
            },
          ],
        }

        myChart1.setOption(option)
        window.addEventListener('resize', () => {
          myChart1.resize()
        })
      })
    },
    renderProjectRating(data) {
      this.$nextTick(() => {
        var myChart = this.$echarts.init(document.getElementById('chart2'))
        var color = ['#2C82BE', '#76DDFB', '#FFCC99', '#DEE5F4']
        var temp = []

        //---假数据（后续使用后台接口时，直接删除该段代码即可---begin）---
        data.num = [1, 1, 0, 2]
        data.rate = [0.25, 0.25, 0, 0.5]
        data.total = 4
        //---假数据（后续使用后台接口时，直接删除该段代码即可---end）---

        if (data && data.level)
          data.level.map(function (v, i) {
            temp.push({
              value: data.num[i],
              name:
                data.level[i] +
                '  ' +
                data.num[i] +
                '个' +
                '  ' +
                (data.rate[i] * 100).toFixed(2) +
                // data.rate[i] * 100 +
                '%',
              itemStyle: {
                color: color[i],
                opacity: 0.9,
              },
            })
          })

        myChart.setOption({
          tooltip: {
            padding: 10,
            formatter: function (params) {
              return params.marker + params.name
            },
          },
          legend: {
            top: '32%',
            left: '72%',
            itemWidth: 16,
            itemHeight: 16,
            width: '20',
            data: temp,
            textStyle: {
              lineHeight: 25,
              fontFamily: 'SourceHanSansCN-Medium',
              fontSize: 16,
            },
          },
          series: [
            {
              name: '',
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: true,
              label: {
                normal: {
                  show: false,
                  position: 'center',
                },
              },
              data: temp,
            },
          ],
          graphic: [
            {
              type: 'text',
              left: 'center',
              top: '45%',
              z: 10,
              zlevel: 10,
              style: {
                text: data.total + '个',
                fill: '#23C4FF',
                textAlign: 'center',
                font: 'bold 28px/34px DIN-Bold',
              },
            },
            {
              type: 'text',
              left: 'center',
              top: '55%',
              z: 10,
              zlevel: 10,
              style: {
                text: '在建评分项目',
                fill: '#666',
                textAlign: 'center',
                font: 'bold 16px/20px PingFang-SC-Semibold',
              },
            },
          ],
        })
        window.addEventListener('resize', () => {
          myChart.resize()
        })
      })
    },
    renderGovAffairIndicator(data) {
      //拼接假数据
      var dataList = [
        {
          accountScale: 0,
          date: '2019年9月',
          depositScale: 0,
          issueScale: 0,
          projectCount: 0,
          realNameScale: 0,
        },
        {
          accountScale: 0,
          date: '2019年10月',
          depositScale: 0,
          issueScale: 0,
          projectCount: 0,
          realNameScale: 0,
        },
        {
          accountScale: 0,
          date: '2019年11月',
          depositScale: 0,
          issueScale: 0,
          projectCount: 0,
          realNameScale: 0,
        },
        {
          accountScale: 0,
          date: '2019年12月',
          depositScale: 0,
          issueScale: 0,
          projectCount: 3,
          realNameScale: 0,
        },
        {
          accountScale: 0.8,
          date: '2020年1月',
          depositScale: 0.6,
          issueScale: 0.2,
          projectCount: 5,
          realNameScale: 0.6,
        },
        {
          accountScale: 0.8,
          date: '2020年2月',
          depositScale: 0.6,
          issueScale: 0.2,
          projectCount: 5,
          realNameScale: 0.6,
        },
      ]
      // var Bdata = data.concat(dataList)
      //拼接假数据
      this.$nextTick(() => {
        var color = ['#76DDFB', '#2C82BE', '#2CBEB3', '#F6BD16', '#2D39BE']
        var myChart = this.$echarts.init(document.getElementById('chart3'))
        var dateList = []
        var projectCountList = []
        var depositScaleList = []
        var realNameScaleList = []
        var accountScaleList = []
        var issueScaleList = []
        var nameList = [
          '保证金覆盖率',
          '实名制覆盖率',
          '工资专户覆盖率',
          '银行代发覆盖率',
        ]
        dataList.map(function (item) {
          dateList.push(item.date)
          projectCountList.push(item.projectCount)
          depositScaleList.push(item.depositScale)
          realNameScaleList.push(item.realNameScale)
          accountScaleList.push(item.accountScale)
          issueScaleList.push(item.issueScale)
        })

        //---假数据（后续使用后台接口时，直接删除该段代码即可---begin）---
        // projectCountList = [180, 182, 185, 190, 193, 199];
        // depositScaleList = [0.9, 0.93, 0.92, 0.9, 0.94, 1];
        // realNameScaleList = [1, 1, 1, 1, 1, 1];
        // accountScaleList = [0.92, 0.88, 0.9, 0.94, 0.92, 0.99];
        // issueScaleList = [0.97, 0.95, 0.97, 0.98, 0.96, 1];
        //---假数据（后续使用后台接口时，直接删除该段代码即可---end）---

        var maxProjectCountList = Math.max.apply(null, projectCountList)
        var minProjectCountList = Math.min.apply(null, projectCountList)

        var list = depositScaleList
          .concat(realNameScaleList)
          .concat(accountScaleList)
          .concat(issueScaleList)
        var max = Math.max.apply(null, list)
        var min = Math.min.apply(null, list)

        minProjectCountList =
          minProjectCountList - 20 > 0
            ? minProjectCountList - 20
            : minProjectCountList
        min = min - 0.1 > 0 ? min - 0.1 : min

        var option = {
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              // 坐标轴指示器，坐标轴触发有效
              type: 'line', // 默认为直线，可选为：'line' | 'shadow'
            },
            formatter: function (params) {
              var str = ''
              params.map(function (item, index) {
                if (index === 0) {
                  str +=
                    item.name +
                    '<br/>' +
                    item.seriesName +
                    '：' +
                    item.data +
                    '<br/>'
                } else if (index < params.length - 1) {
                  str +=
                    item.seriesName +
                    '：' +
                    (item.data * 100).toFixed(1) +
                    '%' +
                    '<br/>'
                } else {
                  str +=
                    item.seriesName + '：' + (item.data * 100).toFixed(1) + '%'
                }
              })
              return str
            },
          },
          legend: {
            data: nameList,
            top: '85%',
            left: 'center',
            padding: [0, 50, 0, 0],
            itemWidth: 20,
            itemGap: 20,
            // top :2000
          },
          // color: color,
          grid: {
            left: '3%',
            right: '4%',
            bottom: '20%',
            top: '15%',
            containLabel: true,
          },
          xAxis: [
            {
              type: 'category',
              data: dateList,
            },
          ],
          yAxis: [
            {
              type: 'value',
              name: '覆盖率',
              max: max,
              min: min,
              axisLabel: {
                show: true,
                interval: 0,
                formatter: function (params) {
                  return params * 100 + '%'
                },
              },
            },
            {
              type: 'value',
              scale: true,
              name: '在建项目总数',
              max: maxProjectCountList,
              min: minProjectCountList,
              // axisLabel:{
              //    show: false,
              // },
              boundaryGap: [0.2, 0.2],
              splitLine: {
                //网格线
                show: false,
              },
            },
          ],
          series: [
            {
              name: '在建项目总数',
              barWidth: '35%',
              type: 'bar',
              yAxisIndex: 1,
              data: projectCountList,
              itemStyle: {
                normal: {
                  color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                    { offset: 0, color: '#76DDFB' }, //柱图渐变色
                    { offset: 1, color: '#53A8E2' }, //柱图渐变色
                  ]),
                },
              },
            },
            {
              name: nameList[0],
              type: 'line',
              yAxisIndex: 0,
              data: depositScaleList,
              itemStyle: {
                normal: {
                  color: color[1],
                },
              },
            },
            {
              name: nameList[1],
              type: 'line',
              yAxisIndex: 0,
              data: realNameScaleList,
              itemStyle: {
                normal: {
                  color: color[2],
                },
              },
            },
            {
              name: nameList[2],
              type: 'line',
              yAxisIndex: 0,
              data: accountScaleList,
              itemStyle: {
                normal: {
                  color: color[3],
                },
              },
            },
            {
              name: nameList[3],
              type: 'line',
              yAxisIndex: 0,
              data: issueScaleList,
              itemStyle: {
                normal: {
                  color: color[4],
                },
              },
            },
          ],
        }
        myChart.setOption(option)
        window.addEventListener('resize', () => {
          myChart.resize()
        })
      })
    },
  },
}
</script>

<style scoped lang="less">
.containerBox {
  height: 89.2%;
  overflow: auto;
  .container {
    .title {
      line-height: 27px;
      font-family: SourceHanSansCN-Medium;
      font-size: 18px;
      font-weight: bold;
      color: #333;
      .projectsRatingIcon {
        font-size: 20px;
        position: relative;
        top: 1px;
      }
    }

    .filterBox {
      padding: 20px 30px 20px 30px;
      background: #fff;
      font: 16px SourceHanSansCN-Normal;
      color: #666;
    }
    .leftContent {
      width: 75%;
      .realTimeMonitoring {
        padding: 20px 30px 20px 30px;
        width: 100%;
        margin-top: 20px;
        background: #fff;
        .options {
          float: right;
          text-align: right;
          width: 85%;
          line-height: 27px;
          font-size: 14px;
          color: #666;
          // float:right;

          > div {
            display: inline-block;
            cursor: pointer;
          }
          .greenLine {
            position: relative;
            top: 5px;
            width: 74%;
            height: 2px;
            background: #009588;
            border-radius: 1px;
          }
        }
        .chartBox {
          width: 55%;
          margin-right: 10px;
          .chartBoxTitle {
            margin-top: 35px;
            margin-bottom: 20px;
            line-height: 17px;
            font-family: SourceHanSansCN-Regular;
            font-size: 11.38px;
            color: #a0a4aa;
          }
          .chart1 {
            width: 100%;
            height: 400px;
          }
        }
        .searchBox {
          float: right;
          width: 40%;
          .projectBox {
            padding: 20px 20px 0 0;
            height: 450px;
            .inputBox {
              text-align: center;
              width: 100%;
              margin-bottom: 20px;
            }
            .projects {
              margin-left: 10px;
              margin-bottom: 10px;
              height: 21px;
              cursor: pointer;
              .normalLevel {
                border: 1px solid #5fab2b;
                font-family: SourceHanSansCN-Regular;
                font-size: 12px;
                color: #5fab2c;
                padding: 1px 0;
                width: 8%;
                height: 100%;
                text-align: center;
              }
              .warningLevel {
                border: 1px solid #e02020;
                font-family: SourceHanSansCN-Regular;
                font-size: 12px;
                color: #e02020;
                padding: 1px 0;
                width: 8%;
                height: 100%;
                text-align: center;
              }
              .projectName {
                width: 88%;
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;
                // margin-left: 10px;
                padding-left: 10px;
                line-height: 20px;
                font-family: SourceHanSansCN-Regular;
                font-size: 14px;
                color: #333;
              }
            }
            .emptyBox {
              text-align: center;
            }
          }
          .paginationBox {
            margin-top: 20px;
            text-align: center;
          }
        }
      }
      .projectsRating {
        padding: 20px 30px 20px 30px;
        width: 100%;
        margin-top: 20px;
        background: #fff;

        .chart2 {
          margin-left: -25%;
          width: 120%;
          height: 400px;
        }
      }
      .govAffairIndicator {
        padding: 20px 30px 20px 30px;
        width: 100%;
        margin-top: 20px;
        background: #fff;

        .chart3 {
          // margin-left: -25%;
          width: 100%;
          height: 550px;
        }
      }
    }
    .rightContent {
      //   margin-top: 20px;
      //   margin-left: 20px;
      width: 25%;
      float: right;
      padding: 20px 0 20px 20px;
      .applicationMarketBox {
        padding: 20px;
        background: #fff;
        .applicationMarket {
          width: 100%;
          height: 65px;
          background: rgba(0, 149, 136, 0.65);
          border-radius: 8px;
          line-height: 65px;
          font-family: SourceHanSansCN-Bold;
          font-size: 22px;
          color: #fff;
          cursor: pointer;
          text-align: center;
          .applicationMarketIcon {
            margin: 3px 10px 0 0;
            font-size: 22px;
          }
        }
        .keyBox {
          margin: 0px 10px 0 10px;
          > div {
            margin-bottom: 10px;
            line-height: 21px;
            font-family: SourceHanSansCN-Regular;
            font-size: 14px;
            color: #333333;
          }
          .titleZw {
            line-height: 27px;
            font-family: SourceHanSansCN-Medium;
            font-size: 18px;
            font-weight: bold;
            color: #333;
          }
        }
      }
      .governmentAssess {
        margin-top: 20px;
        padding: 20px 30px 20px 30px;
        background: #fff;
        .nothing {
          height: 90px;
          font-family: SourceHanSansCN-Regular;
          font-size: 14px;
          color: #999;
          position: relative;
          > div {
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
            width: 90px;
            height: 20px;
          }
        }
      }
    }
  }
}
</style>
